package collection;

import java.util.*;

/**
 * 集合工具类:java.util.Collections
 * 其提供了一个静态方法sort可以对List集合进行自然排序(从小到大)
 */
public class SortListDemo {
    public static void main(String[] args) {
        Random random = new Random();
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            list.add(random.nextInt(100));
        }
        System.out.println(list);
        //按照从小到大排
        Collections.sort(list);
        System.out.println(list);
        //按照从大到小排
        Collections.sort(list,(i1,i2)->i2-i1);
        System.out.println(list);
    }
}
